<?php
/**
* @file $Id: TeacherPrograms.php 518 2007-05-14 07:27:34Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if(UserStaffID())
	echo "<FORM action=Modules.php?modname=$_REQUEST[modname] method=POST>";
DrawHeader(_('Teacher Programs'));

Search('staff_id','teacher');

if(UserStaffID())
{
	$profile = DBGet(DBQuery("SELECT PROFILE FROM USERS WHERE STAFF_ID='".UserStaffID()."'"));
	if($profile[1]['PROFILE']!='teacher')
	{
		unset($_SESSION['staff_id']);
		echo '<script language=JavaScript>parent.side.location="'.$_SESSION['Side_PHP_SELF'].'?modcat="+parent.side.document.forms[0].modcat.value;</script>';
		Search('staff_id','teacher');
	}

	$QI = DBQuery("SELECT DISTINCT cp.PERIOD_ID,cp.COURSE_PERIOD_ID,sp.TITLE,sp.SHORT_NAME,cp.MARKING_PERIOD_ID,cp.DAYS,sp.SORT_ORDER,c.TITLE AS COURSE_TITLE FROM COURSE_PERIODS cp, SCHOOL_PERIODS sp,COURSES c WHERE c.COURSE_ID=cp.COURSE_ID AND cp.PERIOD_ID=sp.PERIOD_ID AND cp.SYEAR='".UserSyear()."' AND cp.SCHOOL_ID='".UserSchool()."' AND cp.TEACHER_ID='".UserStaffID()."' ORDER BY sp.SORT_ORDER ");
	$RET = DBGet($QI);
	// get the fy marking period id, there should be exactly one fy marking period
	$fy_id = DBGet(DBQuery("SELECT MARKING_PERIOD_ID FROM SCHOOL_YEARS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."'"));
	$fy_id = $fy_id[1]['MARKING_PERIOD_ID'];

	if($_REQUEST['period'])
		$_SESSION['UserCoursePeriod'] = $_REQUEST['period'];

	if(!UserPeriod())
		$_SESSION['UserPeriod'] = $RET[1]['PERIOD_ID'];
	if(!UserCoursePeriod())
		$_SESSION['UserCoursePeriod'] = $RET[1]['COURSE_PERIOD_ID'];

	$period_select = "<SELECT name=period onChange='this.form.submit();'>";
	foreach($RET as $period)
	{
		$period_select .= "<OPTION value=$period[COURSE_PERIOD_ID]".((UserCoursePeriod()==$period['COURSE_PERIOD_ID'])?' SELECTED':'').">".$period['SHORT_NAME'].($period['MARKING_PERIOD_ID']!=$fy_id?' '.GetMP($period['MARKING_PERIOD_ID'],'SHORT_NAME'):'').(strlen($period['DAYS'])<5?' '.$period['DAYS']:'').' - '.$period['COURSE_TITLE']."</OPTION>";
		if(UserCoursePeriod()==$period['COURSE_PERIOD_ID'])
		{
			$_SESSION['UserPeriod'] = $period['PERIOD_ID'];
		}
	}
	$period_select .= "</SELECT>";

	DrawHeader($period_select);
	echo '</FORM><BR>';
	unset($_FOCUS['DrawHeader']);

	$_FOCUS['User'][1] = array('STAFF_ID'=>UserStaffID(),'NAME'=>GetTeacher(UserStaffID()),'USERNAME'=>GetTeacher(UserStaffID(),'','USERNAME'),'PROFILE'=>'teacher','SCHOOL_ID'=>UserSchool());

	echo '<CENTER><TABLE width=90% style="border:1px solid #000000"><TR><TD>';

	include('modules/'.$_REQUEST['include']);

	echo '</TD></TR></TABLE></CENTER>';
}
?>